home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / gsview08.zip / DIALOG.C < prev    next >
C/C++ Source or Header  |  1993-07-06  |  19KB  |  638 lines

  1. /*
  2.  * dialog.c -- General dialog boxes for GSVIEW.EXE, 
  3.  *              a graphical interface for MS-Windows Ghostscript
  4.  * Copyright (C) 1993  Russell Lang
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  *   Author: Russell Lang
  21.  * Internet: rjl@monu1.cc.monash.edu.au
  22.  */
  23.  
  24. #define STRICT
  25. #include <windows.h>
  26. #include <windowsx.h>
  27. #include <commdlg.h>
  28. #include <shellapi.h>
  29. #include <mmsystem.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <ctype.h>
  34. #include <dir.h>
  35. #include <io.h>
  36. #define NeedFunctionPrototypes 1
  37. #include "ps.h"
  38. #include "gsview.h"
  39.  
  40.  
  41. BOOL
  42. getfilename(LPSTR filename, BOOL save, UINT filter, UINT title, UINT help)
  43. {
  44. LPSTR old_lpstrFile;
  45. LPCSTR old_lpstrTitle;
  46. char szTitle[MAXSTR];
  47. BOOL flag;
  48.     if (help)
  49.         LoadString(phInstance, help, szHelpTopic, sizeof(szHelpTopic));
  50.     old_lpstrTitle = ofn.lpstrTitle;
  51.     if (title) {
  52.         LoadString(phInstance, title, szTitle, sizeof(szTitle));
  53.         ofn.lpstrTitle = (LPCSTR)szTitle;
  54.     }
  55.     old_lpstrFile = ofn.lpstrFile;
  56.     if (filename != (LPSTR)NULL)
  57.         ofn.lpstrFile = filename;
  58.     ofn.nFilterIndex = filter;
  59.     if (save)
  60.         flag = GetSaveFileName(&ofn);
  61.     else
  62.         flag = GetOpenFileName(&ofn);
  63.     ofn.lpstrTitle = old_lpstrTitle;
  64.     ofn.lpstrFile = old_lpstrFile;
  65.     ofn.nFilterIndex = FILTER_PS;
  66.     if ( save && flag && 
  67.             (dfname[0]!='\0') && (lstrcmp(filename, dfname) == 0) ) {
  68.         gserror(IDS_NOTDFNAME, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
  69.         flag = FALSE;
  70.     }
  71.     return flag;
  72. }
  73.  
  74. /* Input Dialog Box structures */
  75. LPSTR input_prop = "input_prop";
  76. struct input_param {
  77.     LPSTR prompt;
  78.     LPSTR answer;
  79. };
  80.  
  81. BOOL
  82. get_string(char *prompt, char *answer)
  83. {
  84. struct input_param param;
  85. DLGPROC lpProcInput;
  86. BOOL flag;
  87.     param.answer = answer;
  88.     param.prompt = prompt;
  89.     lpProcInput = (DLGPROC)MakeProcInstance((FARPROC)InputDlgProc, phInstance);
  90.     flag = DialogBoxParam( phInstance, "InputDlgBox", hwndimg, lpProcInput, (LPARAM)¶m);
  91.     FreeProcInstance((FARPROC)lpProcInput);
  92.     return flag;
  93. }
  94.  
  95.  
  96. /* input string dialog box */
  97. BOOL CALLBACK _export
  98. InputDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  99. {
  100.     switch(message) {
  101.         case WM_INITDIALOG:
  102.         {
  103.           HLOCAL hlocal;
  104.           LPSTR *panswer;
  105.           struct input_param *pparam = (struct input_param *)lParam;
  106.           SetDlgItemText(hDlg, ID_PROMPT, pparam->prompt);
  107.           SetDlgItemText(hDlg, ID_ANSWER, pparam->answer);
  108.           /* save address of answer string in property list */
  109.           hlocal = LocalAlloc(LHND, sizeof(pparam->answer));
  110.           panswer = (LPSTR *)LocalLock(hlocal);
  111.           if (panswer != (LPSTR *)NULL) {
  112.             *panswer = pparam->answer;
  113.         LocalUnlock(hlocal);
  114.             SetProp(hDlg, input_prop, (HANDLE)hlocal);
  115.           }
  116.         }
  117.             return( TRUE);
  118.         case WM_COMMAND:
  119.             switch(LOWORD(wParam)) {
  120.         case ID_HELP:
  121.             SendMessage(hwndimg, help_message, 0, 0L);
  122.             return(FALSE);
  123.                 case ID_ANSWER:
  124.                     return(TRUE);
  125.         case IDOK:
  126.             {
  127.               HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop); 
  128.               LPSTR *panswer;
  129.                   panswer = (LPSTR *)LocalLock(hlocal);
  130.                   if (panswer != (LPSTR *)NULL) {
  131.                 GetDlgItemText(hDlg, ID_ANSWER, *panswer, MAXSTR);
  132.             LocalUnlock(hlocal);
  133.               }
  134.               LocalFree(hlocal);
  135.               RemoveProp(hDlg, input_prop);
  136.             }
  137.                     EndDialog(hDlg, TRUE);
  138.                     return(TRUE);
  139.                 case IDCANCEL:
  140.             {
  141.               HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop); 
  142.               LocalFree(hlocal);
  143.               RemoveProp(hDlg, input_prop);
  144.             }
  145.                     EndDialog(hDlg, FALSE);
  146.                     return(TRUE);
  147.                 default:
  148.                     return(FALSE);
  149.             }
  150.         default:
  151.             return(FALSE);
  152.     }
  153. }
  154.  
  155.  
  156. /* copyright dialog box */
  157. BOOL CALLBACK _export
  158. AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  159. {
  160.     switch(message) {
  161.         case WM_INITDIALOG:
  162.             SetDlgItemText(hDlg, ABOUT_VERSION, GSVIEW_VERSION);
  163.             return( TRUE);
  164.     case WM_LBUTTONDBLCLK:
  165.         {DWORD dwUnit = GetDialogBaseUnits();
  166.         RECT rect; POINT pt;
  167.         pt.x = LOWORD(lParam); pt.y = HIWORD(lParam);
  168.         rect.left   =   8 * LOWORD(dwUnit) / 4;
  169.         rect.top    = 138 * HIWORD(dwUnit) / 8;
  170.         rect.right  = 240 * LOWORD(dwUnit) / 4 + rect.left;
  171.         rect.bottom =   8 * HIWORD(dwUnit) / 8 + rect.top;
  172.         if (PtInRect(&rect,pt)) {
  173.         BITMAP bm;
  174.         HBITMAP hbitmap_old;
  175.         HBITMAP hbitmap = LoadBitmap(phInstance,"gsview_bitmap");
  176.         HDC hdc = GetDC(hDlg);
  177.         HDC hdcsrc = CreateCompatibleDC(hdc);
  178.         hbitmap_old = SelectObject(hdcsrc,hbitmap);
  179.         GetObject(hbitmap, sizeof(BITMAP),&bm);
  180.         BitBlt(hdc, rect.right-bm.bmWidth,rect.bottom-bm.bmHeight,
  181.            bm.bmWidth,bm.bmHeight,hdcsrc,0,0,SRCCOPY);
  182.         SelectObject(hdcsrc,hbitmap_old);
  183.         DeleteObject(hbitmap);
  184.         DeleteDC(hdcsrc);
  185.         ReleaseDC(hDlg,hdc);
  186.         }
  187.         }
  188.         return FALSE;
  189.         case WM_COMMAND:
  190.             switch(LOWORD(wParam)) {
  191.                 case IDOK:
  192.                     EndDialog(hDlg, TRUE);
  193.                     return(TRUE);
  194.                 default:
  195.                     return(FALSE);
  196.             }
  197.         default:
  198.             return(FALSE);
  199.     }
  200. }
  201.  
  202. /* information about document dialog box */
  203. BOOL CALLBACK _export
  204. InfoDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  205. {
  206.     switch(message) {
  207.         case WM_INITDIALOG:
  208.       { char buf[MAXSTR];
  209.         int n;
  210.         if (dfname[0] != '\0') {
  211.                 SetDlgItemText(hDlg, INFO_FILE, dfname);
  212.         if (doc) {
  213.             if (is_ctrld)
  214.             LoadString(phInstance, IDS_NOTDSC, buf, sizeof(buf));
  215.             else  {
  216.             if (doc->epsf) {
  217.                 switch (preview) {
  218.                 case IDS_EPSI:
  219.                   LoadString(phInstance, IDS_EPSI, buf, sizeof(buf));
  220.                   break;
  221.                 case IDS_EPST:
  222.                   LoadString(phInstance, IDS_EPST, buf, sizeof(buf));
  223.                   break;
  224.                 case IDS_EPSW:
  225.                   LoadString(phInstance, IDS_EPSW, buf, sizeof(buf));
  226.                   break;
  227.                 default:
  228.                   LoadString(phInstance, IDS_EPSF, buf, sizeof(buf));
  229.                 }
  230.             }
  231.             else
  232.                 LoadString(phInstance, IDS_DSC, buf, sizeof(buf));
  233.             }
  234.                     SetDlgItemText(hDlg, INFO_TYPE, buf);
  235.             SetDlgItemText(hDlg, INFO_TITLE, doc->title ? doc->title : "");
  236.             SetDlgItemText(hDlg, INFO_DATE, doc->date ? doc->date : "");
  237.             sprintf(buf, "%d %d %d %d", doc->boundingbox[LLX], doc->boundingbox[LLY], 
  238.             doc->boundingbox[URX], doc->boundingbox[URY]);
  239.             SetDlgItemText(hDlg, INFO_BBOX, buf);
  240.             switch(doc->orientation) {
  241.             case LANDSCAPE:
  242.                     LoadString(phInstance, IDS_LANDSCAPE, buf, sizeof(buf));
  243.                 break;
  244.             case PORTRAIT:
  245.                     LoadString(phInstance, IDS_PORTRAIT, buf, sizeof(buf));
  246.                 break;
  247.             default:
  248.                 buf[0] = '\0';
  249.             }
  250.             SetDlgItemText(hDlg, INFO_ORIENT, buf);
  251.             switch(doc->pageorder) {
  252.             case ASCEND: 
  253.                     LoadString(phInstance, IDS_ASCEND, buf, sizeof(buf));
  254.                 break;
  255.             case DESCEND: 
  256.                     LoadString(phInstance, IDS_DESCEND, buf, sizeof(buf));
  257.                 break;
  258.             case SPECIAL:
  259.                     LoadString(phInstance, IDS_SPECIAL, buf, sizeof(buf));
  260.                 break;
  261.             default:
  262.                 buf[0] = '\0';
  263.             }
  264.             SetDlgItemText(hDlg, INFO_ORDER, buf);
  265.             if (doc->default_page_media && doc->default_page_media->name) {
  266.                 sprintf(buf,"%s %d %d",doc->default_page_media->name,
  267.                     doc->default_page_media->width,
  268.                     doc->default_page_media->height);
  269.             }
  270.             else {
  271.             buf[0] = '\0';
  272.             }
  273.             SetDlgItemText(hDlg, INFO_DEFMEDIA, buf);
  274.             sprintf(buf, "%d", doc->numpages);
  275.             SetDlgItemText(hDlg, INFO_NUMPAGES, buf);
  276.             n = map_page(pagenum - 1);
  277.             if (doc->pages)
  278.                 sprintf(buf, "\"%s\"   %d", doc->pages[n].label ? doc->pages[n].label : "", pagenum);
  279.             else
  280.                 buf[0] = '\0';
  281.             SetDlgItemText(hDlg, INFO_PAGE, buf);
  282.         
  283.         }
  284.         else {
  285.             LoadString(phInstance, IDS_NOTDSC, buf, sizeof(buf));
  286.                     SetDlgItemText(hDlg, INFO_TYPE, buf);
  287.         }
  288.         sprintf(buf, "%d \327 %d", bitmap_width, bitmap_height);
  289.         SetDlgItemText(hDlg, INFO_BITMAP, buf);
  290.         }
  291.         else {
  292.             LoadString(phInstance, IDS_NOFILE, buf, sizeof(buf));
  293.                 SetDlgItemText(hDlg, INFO_FILE, buf);
  294.        }
  295.       }
  296.           return( TRUE);
  297.     case WM_COMMAND:
  298.             switch(LOWORD(wParam)) {
  299.                 case IDOK:
  300.                     EndDialog(hDlg, TRUE);
  301.                     return(TRUE);
  302.                 case IDCANCEL:
  303.                     EndDialog(hDlg, FALSE);
  304.                     return(TRUE);
  305.                 default:
  306.                     return(FALSE);
  307.             }
  308.         default:
  309.             return(FALSE);
  310.     }
  311. }
  312.  
  313.  
  314. #define MAX_SYSTEM_SOUND 16
  315. char *system_sounds;
  316. char *sound_entry[MAX_SYSTEM_SOUND];
  317. char szNone[32];
  318. char szSpeaker[32];
  319. int system_num;
  320.  
  321. int
  322. load_sounds(void)
  323. {
  324.     char *p;
  325.     int j;
  326.  
  327.     /* add our two sounds */
  328.     sound_entry[0] = "";
  329.     sound_entry[1] = BEEP;
  330.     LoadString(phInstance, IDS_NONE, szNone, sizeof(szNone));
  331.     LoadString(phInstance, IDS_SPKR, szSpeaker, sizeof(szSpeaker));
  332.     /* get list of system sounds */
  333.     system_sounds = malloc(PROFILE_SIZE);
  334.     if (system_sounds != (char *)NULL) {
  335.         GetProfileString("sounds", NULL, "", system_sounds, PROFILE_SIZE);
  336.     }
  337.     p = system_sounds;
  338.     for (j=2; p!=(char *)NULL && j<MAX_SYSTEM_SOUND && strlen(p)!=0; j++) {
  339.         sound_entry[j] = p;    
  340.         p += strlen(p) + 1;
  341.     }
  342.     system_num = j;
  343.     return system_num;
  344. }
  345.  
  346. char *
  347. get_sound_entry(int index)
  348. {
  349.     return (sound_entry[index]);
  350. }
  351.  
  352. char *
  353. get_sound_name(int index)
  354. {
  355. static char buf[64];
  356. char *p;
  357.     if (index==0)
  358.         return szNone;
  359.     if (index==1)
  360.         return szSpeaker;
  361.         GetProfileString("sounds", sound_entry[index], ",", buf, sizeof(buf));
  362.         p = strchr(buf,',');
  363.         if (p != (char *)NULL)
  364.         return p+1;
  365.     return (char *)NULL;
  366. }
  367.  
  368. int 
  369. find_sound_name(char *entry)
  370. {
  371. int i;
  372.     for (i=0; i<system_num; i++) {
  373.         if (strcmp(entry, sound_entry[i])==0)
  374.             return i;
  375.     }
  376.     return -1;    /* no find */
  377. }
  378.  
  379. void
  380. add_sounds(HWND hDlg)
  381. {
  382. int ifile;
  383.     for (ifile=system_num-1; ifile>=0; ifile--)
  384.         SendDlgItemMessage(hDlg, SOUND_FILE, LB_INSERTSTRING, 0,
  385.              (LPARAM)(LPSTR)get_sound_name(ifile));
  386. }
  387.  
  388. void
  389. free_sounds(void)
  390. {
  391.     if (system_sounds != (char *)NULL)
  392.         free(system_sounds);
  393. }
  394.  
  395. BOOL CALLBACK _export
  396. SoundDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
  397. {
  398.     char buf[MAXSTR];
  399.     int ievent, ifile;
  400.     static struct sound_s dsound[NUMSOUND];    /* copy of sound[] */
  401.     WORD notify_message;
  402.     char *szWaveFilter = "*.wav";
  403.     static char szPath[MAXSTR];
  404.     static int file_start;
  405.     char *p;
  406.  
  407.     switch (wmsg) {
  408.         case WM_INITDIALOG:
  409.         file_start = load_sounds();
  410.         for (ievent=0; ievent<NUMSOUND; ievent++) {
  411.             strcpy(dsound[ievent].file, sound[ievent].file);
  412.             LoadString(phInstance, sound[ievent].title, buf, sizeof(buf));
  413.             SendDlgItemMessage(hDlg, SOUND_EVENT, LB_ADDSTRING, 0, 
  414.             (LPARAM)((LPSTR)buf));
  415.         }
  416.         ievent = 0;
  417.         SendDlgItemMessage(hDlg, SOUND_EVENT, LB_SETCURSEL, ievent, 0L);
  418.         /* force update of SOUND_FILE */
  419.         SendDlgNotification(hDlg, SOUND_EVENT, LBN_SELCHANGE);
  420.         return TRUE;
  421.         case WM_COMMAND:
  422.         notify_message = GetNotification(wParam,lParam);
  423.         switch (LOWORD(wParam)) {
  424.             case ID_HELP:
  425.                 SendMessage(hwndimg, help_message, 0, 0L);
  426.                 return(FALSE);
  427.             case SOUND_EVENT:
  428.             if (notify_message != LBN_SELCHANGE) {
  429.                 return FALSE;
  430.             }
  431.             ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  432.             if (ievent == LB_ERR) {
  433.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), FALSE);
  434.                 return FALSE;
  435.             }
  436.             ifile = find_sound_name(dsound[ievent].file);
  437.             if (ifile >= 0) {
  438.                 strcpy(buf, get_sound_name(ifile));
  439.                 szPath[0] = '\0';
  440.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), ifile!=0);
  441.             }
  442.             else {
  443.                 /* must be WAVE file */
  444.                 strcpy(szPath, dsound[ievent].file);
  445.                 p = strrchr(szPath, '\\');
  446.                 if (p != (char *)NULL) {
  447.                     strcpy(buf,++p);
  448.                     *p = '\0';
  449.                 }
  450.                 else {
  451.                     strcpy(buf, szPath);
  452.                 }
  453.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), TRUE);
  454.             }
  455.             strcat(szPath, szWaveFilter);
  456.             DlgDirList(hDlg, szPath, SOUND_FILE, SOUND_PATH, DDL_DRIVES | DDL_DIRECTORY);
  457.             add_sounds(hDlg);
  458.             SendDlgItemMessage(hDlg, SOUND_FILE, LB_SELECTSTRING, file_start, (LPARAM)(LPSTR)buf);
  459.             return FALSE;
  460.             case SOUND_FILE:
  461.             if (notify_message == LBN_SELCHANGE) {
  462.                 ifile = (int)SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETCURSEL, 0, 0L);
  463.                 SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETTEXT, ifile, (LPARAM)(LPSTR)buf);
  464.                 ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  465.                 if (ifile >= file_start) {
  466.                 if (buf[0] == '[') { /* selected a directory */
  467.                     EnableWindow(GetDlgItem(hDlg, SOUND_TEST), FALSE);
  468.                     }
  469.                 else { /* selected a WAVE file */
  470.                             int i = GetDlgItemText(hDlg, SOUND_PATH, dsound[ievent].file, MAXSTR);
  471.                         if (dsound[ievent].file[i-1] != '\\')
  472.                             dsound[ievent].file[i++] = '\\';
  473.                             DlgDirSelect(hDlg, dsound[ievent].file + i, SOUND_FILE);
  474.                     EnableWindow(GetDlgItem(hDlg, SOUND_TEST), TRUE);
  475.                 }
  476.                 }
  477.                 else {
  478.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), ifile!=0);
  479.                 strcpy(dsound[ievent].file,get_sound_entry(ifile));
  480.                 }
  481.             }
  482.             if (notify_message == LBN_DBLCLK) {
  483.                 ifile = (int)SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETCURSEL, 0, 0L);
  484.                 SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETTEXT, ifile, (LPARAM)(LPSTR)buf);
  485.                 if (buf[0] == '[') {
  486.                         DlgDirSelect(hDlg, szPath, SOUND_FILE);
  487.                     lstrcat(szPath, szWaveFilter);
  488.                         DlgDirList(hDlg, szPath, SOUND_FILE, SOUND_PATH, DDL_DRIVES | DDL_DIRECTORY);
  489.                 add_sounds(hDlg);
  490.                 }
  491.                 else {
  492.                 SendDlgNotification(hDlg, SOUND_TEST, BN_CLICKED);
  493.                 }
  494.             }
  495.             return FALSE;
  496.             case SOUND_TEST:
  497.             ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  498.             if (strlen(dsound[ievent].file)==0)
  499.                 return FALSE;
  500.             if (!is_win31 || (strcmp(dsound[ievent].file,BEEP)==0)) {
  501.                 MessageBeep(-1);
  502.                 return FALSE;
  503.             }
  504.             if (is_win31) {
  505.                 if (lpfnSndPlaySound != (FPSPS)NULL) 
  506.                         lpfnSndPlaySound(dsound[ievent].file, SND_SYNC);
  507.                 else
  508.                     MessageBeep(-1);
  509.                 return FALSE;
  510.             }
  511.             return FALSE;
  512.             case IDOK:
  513.             for (ievent=0; ievent<NUMSOUND; ievent++)
  514.                 strcpy(sound[ievent].file, dsound[ievent].file);
  515.             free_sounds();
  516.             EndDialog(hDlg, TRUE);
  517.             return TRUE;
  518.             case IDCANCEL:
  519.             free_sounds();
  520.             EndDialog(hDlg, FALSE);
  521.             return TRUE;
  522.         }
  523.         break;
  524.     }
  525.     return FALSE;
  526. }
  527.  
  528. /* Get page number from dialog box and store in ppage */
  529. BOOL
  530. get_page(int *ppage, BOOL multiple)
  531. {
  532. DLGPROC lpProcPage;
  533. BOOL flag;
  534.     if (doc == (struct document *)NULL)
  535.         return FALSE;
  536.     if (doc->numpages == 0) {
  537.         gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER);
  538.         return FALSE;
  539.     }
  540.     page_list.current = *ppage - 1;
  541.     page_list.multiple = multiple;
  542.     if (page_list.select == (BOOL *)NULL)
  543.         return FALSE;
  544.     memset(page_list.select, 0, doc->numpages * sizeof(BOOL) );
  545.     lpProcPage = (DLGPROC)MakeProcInstance((FARPROC)PageDlgProc, phInstance);
  546.     flag = DialogBoxParam( phInstance, "PageDlgBox", hwndimg, lpProcPage, (LPARAM)NULL);
  547.     FreeProcInstance((FARPROC)lpProcPage);
  548.     if (flag && (page_list.current >= 0))
  549.         *ppage = page_list.current + 1;
  550.     return flag;
  551. }
  552.  
  553. BOOL CALLBACK _export
  554. PageDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
  555. {
  556.     char buf[40];
  557.     int i;
  558.     WORD notify_message;
  559.     switch (wmsg) {
  560.         case WM_INITDIALOG:
  561.         if (page_list.multiple)
  562.             LoadString(phInstance, IDS_SELECTPAGES, buf, sizeof(buf));
  563.         else
  564.             LoadString(phInstance, IDS_SELECTPAGE, buf, sizeof(buf));
  565.         SetWindowText(hDlg, buf);
  566.         for (i=0; i<doc->numpages; i++) {
  567.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_ADDSTRING, 0, 
  568.             (LPARAM)((LPSTR)doc->pages[map_page(i)].label));
  569.         }
  570.         SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, TRUE, MAKELPARAM(page_list.current,0));
  571.         SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETCURSEL, page_list.current, 0L);
  572.         if (!page_list.multiple) {
  573.             EnableWindow(GetDlgItem(hDlg, PAGE_ALL), FALSE);
  574.             EnableWindow(GetDlgItem(hDlg, PAGE_ODD), FALSE);
  575.             EnableWindow(GetDlgItem(hDlg, PAGE_EVEN), FALSE);
  576.         }
  577.         return TRUE;
  578.         case WM_COMMAND:
  579.         notify_message = GetNotification(wParam,lParam);
  580.         switch (LOWORD(wParam)) {
  581.             case PAGE_LIST:
  582.             if (notify_message == LBN_DBLCLK)
  583.                 PostMessage(hDlg, WM_COMMAND, IDOK, 0L);
  584.             return FALSE;
  585.             case PAGE_ALL:
  586.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_SELITEMRANGE, TRUE, 
  587.                 MAKELPARAM(0,doc->numpages-1));
  588.             return FALSE;
  589.             case PAGE_ODD:
  590.             for (i=(int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCOUNT, 0, 0L)-1; i>=0; i--)
  591.                 SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, !(i&1), MAKELPARAM(i,0));
  592.             return FALSE;
  593.             case PAGE_EVEN:
  594.             for (i=(int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCOUNT, 0, 0L); i>=0; i--)
  595.                 SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, (i&1), MAKELPARAM(i,0));
  596.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETTOPINDEX, 0, 0L);
  597.             return FALSE;
  598.             case IDOK:
  599.             i = (int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCURSEL, 0, 0L);
  600.             page_list.current = (i == LB_ERR) ? -1 : i;
  601.             for (i=0; i<doc->numpages; i++) {
  602.               page_list.select[i] =
  603.                 (int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETSEL, i, 0L);
  604.             }
  605.             EndDialog(hDlg, TRUE);
  606.             return TRUE;
  607.             case IDCANCEL:
  608.             EndDialog(hDlg, FALSE);
  609.             return TRUE;
  610.         }
  611.         break;
  612.     }
  613.     return FALSE;
  614. }
  615.  
  616.  
  617.  
  618. /* get user defined size */
  619. BOOL
  620. gsview_usersize()
  621. {
  622. char prompt[MAXSTR];
  623. char answer[MAXSTR];
  624.     LoadString(phInstance, IDS_TOPICMEDIA, szHelpTopic, sizeof(szHelpTopic));
  625.     LoadString(phInstance, IDS_USERWIDTH, prompt, sizeof(prompt));
  626.     sprintf(answer,"%d", user_width);
  627.     if (!get_string(prompt,answer) || atoi(answer)==0)
  628.         return FALSE;
  629.     user_width = atoi(answer);
  630.     LoadString(phInstance, IDS_USERHEIGHT, prompt, sizeof(prompt));
  631.     sprintf(answer,"%d", user_height);
  632.     if (!get_string(prompt,answer) || atoi(answer)==0)
  633.         return FALSE;
  634.     user_height = atoi(answer);
  635.     return TRUE;
  636. }
  637.  
  638.